<?php

//自定义函数threshold方法，生成日历的边界值
//1.计算本月的总天数  2.计算本月的第一天和最后一天，各是星期几   3.计算日历中的第一个日期与最后一个日期

function threshold($year,$month){
	$firstDay = mktime(0,0,0,$month,1,$year);    //返回日期的UNIX时间戳  mktime(hour,minute,second,month,day,year,is_dst);
	$lastDay = strtotime('+1 month -1 day',$firstDay);  //将任何英文文本的日期或时间描述解析为UNIX时间戳  strtotime(time,now);
	$days = date("t",$firstDay);   //取得当前天数
	$firstDayOfWeek = date("N",$firstDay);   //获得第一天是周几
	$lastDayOfWeek = date('N',$lastDay);   //获得最后一天是周几

	$lastMonthDate = strtotime('+1 day',$firstDay);  //上个月最后一天
	$lastMonthOfLastDay = date('d',$lastMonthDate);

	$nextMonthDate = strtotime('+1 day',$lastDay);   //下个月第一天
	$nextMonthOffirstDay = strtotime('+1 day',$lastDay);

	//日历的第一个日期
	if($firstDayOfWeek==7){                
		$firstDate = $firstDay;
	}else{
		$firstDate = strtotime('-'.$firstDayOfWeek.'day',$firstDay);
	}

	//日历的最后一个日期
	if($lastDayOfWeek==6){
		$lastDate = $lastDay;
	}elseif($lastDayOfWeek==7){
		$lastDate = strtotime('+6 day',$lastDay);
	}else{
		$lastDate = strtotime('+'.(6-$lastDayOfWeek).'day',$lastDay);
	}

	return array(
		'days'=>$days,
		'firstDayOfWeek'=>$firstDayOfWeek,
		'lastDayOfWeek'=>$lastDayOfWeek,
		'lastMonthOfLastDay'=>$lastMonthOfLastDay,
		'firstDate'=>$firstDate,
		'lastDate'=>$lastDate,
		'year' =>$yeat,
		'month'=>$month
	);
}
?>